/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.query;


public class Time implements Comparable<Time> {
  public int hour = -1;
  public int minute = -1;
  public int second = -1;

  public Time() {
  }

  public Time(int hour, int minute, int second) {
    this.hour = hour;
    this.minute = minute;
    this.second = second;
  }

  public int compareTo(Time time) {
    if (hour < time.hour)
      return -1;
    if (hour > time.hour)
      return 1;
    if (minute < time.minute)
      return -1;
    if (minute > time.minute)
      return 1;
    if (second < time.second)
      return -1;
    if (second > time.second)
      return 1;
    return 0;
  }
  

  	public static Time processTime(String timeStr) {
		Time time = new Time();
		try {
			int val = timeStr.indexOf(":");
			int val2 = timeStr.indexOf(":", val+1);
			if ( (val > 0) && (val2 > val + 1)) {
		  		// Format is hour:minute:second
		  		time.hour = Integer.parseInt(timeStr.substring(0, val));
		  		time.minute = Integer.parseInt(timeStr.substring(val+1, val2));
		  		time.second = Integer.parseInt(timeStr.substring(val2+1));
		  		return time;
			}
		}
		catch (Exception E) {
			E.printStackTrace();
			return null;
		}
		return null;
	}	

  public String toString() {
    return hour + ":" + minute + ":" + second;
  }

  public String toXML() {
    return "<time start=\"" + this.toString() + "\"/>";
  }
}